//
//  HttpRequest.m
//  Rail
//
//  Created by hychen on 2018/2/25.
//  Copyright © 2018年 Hychen. All rights reserved.
//

#import "HttpRequest.h"


@implementation HttpRequest

//首页数据
+ (void)loadHomeListDataSuccess:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestJavaBeanDataWithParams:@[API_App_Home_List,@{}] authType:AUTH_LOGIN dataType:JSON_NO Success:^(id obj) {
        HomeDataModel *model = [HomeDataModel mj_objectWithKeyValues:obj];
        if (success) {
            success(model);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
    
}

//首页搜索工区
+ (void)searchKeyword:(NSString *)keyword success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    
    if ([keyword objectIsNotEmpty]) {
        [[NetworkTool sharedNetworkTool] requestJavaBeanDataWithParams:@[API_App_Search,@{@"keyword":keyword}] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
            if (success) {
                success(obj);
            }
        } Failure:^(NSString *code, NSString *msg) {
            if (failure) {
                failure(code,msg);
            }
        }];
    }
    
}

//行业资讯
+ (void)loadNewsListDataWithPageNo:(NSString *)pageNo dirId:(NSString *)dirId success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestJavaBeanDataWithParams:@[API_App_News_List,@{@"dirid":dirId,@"pageno":pageNo}] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        NSArray *newsArray = [NewModel mj_objectArrayWithKeyValuesArray:[obj objectForKey:@"list"]];
        if (success) {
            success(newsArray);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//添加收藏
+ (void)addFavWithLineId:(NSString *)lineId areaId:(NSString *)areaId deviceId:(NSString *)deviceId success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure; {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_Fav_Add,lineId?:@"",areaId?:@"",deviceId?:@""] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        obj = [obj objectForKeySafe:@"favid"];
        if (success) {
            success(obj);
        }
        success(obj);
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//取消收藏
+ (void)cancelFavWithFavId:(NSString *)idString success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_Fav_Cancel,idString] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        obj = [obj objectForKeySafe:@"favid"];
        if (success) {
            success(obj);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//收藏栏目列表
+ (void)loadFavGroupListDataSuccess:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_Fav_Dir_List] authType:AUTH_LOGIN dataType:JSON_NO Success:^(id obj) {
        NSArray *array = [FavGroupModel mj_objectArrayWithKeyValuesArray:[obj objectForKey:@"list"]];
        if (success) {
            success(array);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}


//收藏列表
+ (void)loadFavAllListDataSuccess:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_Fav_List] authType:AUTH_LOGIN dataType:JSON_NO Success:^(id obj) {
        NSArray *object = [AllFavListModel mj_objectArrayWithKeyValuesArray:[obj objectForKey:@"list"]];
        if (success) {
            success(object);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//移动收藏分栏
+ (void)moveFavGroupWithFavId:(NSString *)favId groupId:(NSString *)groupId success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_Fav_Move,favId?:@"",groupId?:@""] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        if (success) {
            success(obj);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//添加收藏栏目
+ (void)addFavGroupWithGroupName:(NSString *)groupName success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_Fav_Dir_Add,groupName?:@""] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        NSString *dirId = [obj objectForKey:@"dirid"];
        if (success) {
            success(dirId);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//修改收藏栏目
+ (void)updateFavGroupWithGroupName:(NSString *)groupName groupId:(NSString *)groupId success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_Fav_Dir_Rename,groupId?:@"",groupName?:@""] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        if (success) {
            success(obj);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//删除收藏栏目
+ (void)deleteFavGroupWithGroupId:(NSString *)groupId success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_Fav_Dir_Delete,groupId?:@""] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        if (success) {
            success(obj);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//线路收藏列表
+ (void)loadLineFavDataListSuccess:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_Fav_Line_List] authType:AUTH_LOGIN dataType:JSON_NO Success:^(id obj) {
        NSArray *object = [LineFavModel mj_objectArrayWithKeyValuesArray:[obj objectForKey:@"list"]];
        if (success) {
            success(object);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//设备收藏列表
+ (void)loadDeviceFavDataListSuccess:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_Fav_Device_List] authType:AUTH_LOGIN dataType:JSON_NO Success:^(id obj) {
        NSArray *object = [SelectVideoDeviceModel mj_objectArrayWithKeyValuesArray:[obj objectForKey:@"list"]];
        if (success) {
            success(object);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//工区收藏列表
+ (void)loadWorkAreaFavDataListSuccess:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_Fav_WorkArea_List] authType:AUTH_LOGIN dataType:JSON_NO Success:^(id obj) {
        NSArray *object = [WorkAreaFavModel mj_objectArrayWithKeyValuesArray:[obj objectForKey:@"list"]];
        if (success) {
            success(object);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//上传头像
+ (void)uploadAvatarWithImage:(UIImage *)image success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] uploadIconImgWithParams:@[API_App_User_Update_Avatar,@"logo_avatar"] Img:image Success:^(id obj) {
        if (success) {
            success(obj);
        }
    } Failure:^{
        Show_Msg_Error(@"上传头像失败")
    }];
}

//状态监控
+ (void)loadStatusDeviceListDataWithTypeCode:(NSString *)typeCode lineId:(NSString *)lineId stationId:(NSString *)stationId areaId:(NSString *)areaId success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_Device_Status,typeCode?:@"",lineId?:@"",stationId?:@"",areaId?:@""] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        NSArray *object = [DeviceStatusModel mj_objectArrayWithKeyValuesArray:obj];
        if (success) {
            success(object);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//视频终端列表
+ (void)loadDeviceVideoListDataWithAreaId:(NSString *)areaId status:(NSString *)status pageNo:(NSString *)pageNo success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_Video_Device_List,areaId?:@"",status?:@"",pageNo] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        NSArray *object = [SelectVideoDeviceModel mj_objectArrayWithKeyValuesArray:[obj objectForKey:@"list"]];
        for (SelectVideoDeviceModel *model in object) {
            if ([model isKindOfClass:[SelectVideoDeviceModel class]]) {
                [model setupTypeModel];
            }
        }
        if (success) {
            success(object);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//视频终端详情
+ (void)loadDeviceVideoDetailDataWithDeviceId:(NSString *)deviceId  success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_Video_Device_Detail,deviceId?:@""] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        SelectVideoDeviceModel *object = [SelectVideoDeviceModel mj_objectWithKeyValues:obj];
        [object setupTypeModel];
        if (success) {
            success(object);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//消息 - 报警统计
+ (void)loadInformationWithAlertStatisticSuccess:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestJavaBeanDataWithParams:@[API_App_Alert_Statistic,@{}] authType:AUTH_LOGIN dataType:JSON_NO Success:^(id obj) {
        InformationAlertModel *model = [InformationAlertModel mj_objectWithKeyValues:obj];
        if (success) {
            success(model);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//消息 - 公告通知
+ (void)loadNoticeListWithPage:(NSString *)page success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestJavaBeanDataWithParams:@[API_App_Notice_List,@{@"pageno":page?:@"0"}] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        NSArray *modelArray = [NoticeModel mj_objectArrayWithKeyValuesArray:[obj objectForKey:@"list"]];
        if (success) {
            success(modelArray);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//处理报警
+ (void)handleWarnWithRecordId:(NSString *)recordId text:(NSString *)text success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_Alert_Record_Process,recordId?:@"",text?:@""] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        if (success) {
            success(obj);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//报警记录
+ (void)loadWarnListDataWithStatus:(NSString *)status alertType:(NSString *)alertType eventLevel:(NSString *)eventLevel eventId:(NSString *)eventId pageNo:(NSString *)pageNo success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_Alert_Warn_List,status?:@"",alertType?:@"",eventLevel?:@"",eventId?:@"",pageNo?:@"1"] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        NSArray *object = [WarnDetailModel mj_objectArrayWithKeyValuesArray:[obj objectForKey:@"list"]];
        if (success) {
            success(object);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

+ (void)loadWarnDetailDataWithRecordId:(NSString *)recordId  success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_Alert_Detail,recordId?:@""] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        WarnDetailModel *model = [WarnDetailModel mj_objectWithKeyValues:obj];
        if (success) {
            success(model);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//当前报警记录(消息首页)
+ (void)loadCurrentWarnListDataWithPageNo:(NSString *)pageNo success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestJavaBeanDataWithParams:@[API_App_Alert_Current_Warn_List,@{@"pageno":pageNo}] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        NSArray *object = [WarnDetailModel mj_objectArrayWithKeyValuesArray:[obj objectForKey:@"list"]];
        if (success) {
            success(object);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//报警录入
+ (void)addAlertRecordWithAreaId:(NSString *)areaId deviceId:(NSString *)deviceId deviceName:(NSString *)deviceName chNo:(NSString *)chNo content:(NSString *)content alertType:(NSString *)alertType eventId:(NSString *)eventId eventType:(NSString *)eventType eventLevel:(NSString *)eventLevel startTime:(NSString *)startTime endTime:(NSString *)endTime sourceType:(NSString *)sourceType snapshotImage1:(UIImage *)image1 snapshotImage2:(UIImage *)image2 snapshotImage3:(UIImage *)image3 videoUrl:(NSData *)videoData success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    RequestMessage *req = [[RequestMessage alloc] initWithFunc:API_App_Alert_Record_Add];
    req.header.httpheader = [MessageFactory getHttpHeader];
    req.header.appcode = @"B002";
    [MessageFactory getHttpHeader].authtype = AUTH_LOGIN;
    [req.body setItemWithDictionary:@{
                                      @"areaid":areaId?:@"",
                                      @"deviceid":deviceId?:@"",
                                      @"device_name":deviceName?:@"",
                                      @"ch_no":chNo?:@"",
                                      @"content":content?:@"",
                                      @"alert_type":alertType?:@"",
                                      @"eventid":eventId?:@"",
                                      @"event_type":eventType?:@"",
                                      @"event_level":eventLevel?:@"",
                                      @"start_time":startTime?:@"",
                                      @"end_time":endTime?:@"",
                                      @"source_type":sourceType?:@"",
                                      }.mutableCopy];
    [req.body addImage:@"snapshot_img1" image:image1];
    [req.body addImage:@"snapshot_img2" image:image2];
    [req.body addImage:@"snapshot_img3" image:image3];
    [req.body addMedia:@"video_url" mediaData:videoData extName:@"mp4"];
    
    [MessageFactory doFormPost:req httpresult:^(ResponseMessage *res) {
        if ([res.header.status isEqualToString:@"200"]) {
            success(res.body.data);
        }else {
            failure(@"0",@"提交失败");
        }
        NSLog(@"报警录入结果\nstatus:%@,,info:%@",res.header.status,res.header.info);
    }];
}

//线路查询
+ (void)loadLineListWithKeyword:(NSString *)keyword success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_Line_List] authType:AUTH_LOGIN dataType:JSON_NO Success:^(id obj) {
        NSArray *lineArray = [LineModel mj_objectArrayWithKeyValuesArray:[obj objectForKey:@"list"]];
        if (success) {
            success(lineArray);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//线路层级
+ (void)loadLineDetailTreeWithKeyword:(NSString *)keyword lineId:(NSString *)lineId lineStatus:(NSString *)lineStatus success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestJavaBeanDataWithParams:@[API_App_Line_Tree,@{@"key":keyword?:@"",@"lineid":lineId?:@"",@"status":lineStatus?:@""}] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        NSArray *array = [LineDetailModel mj_objectArrayWithKeyValuesArray:obj];
        if (success) {
            success(array);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//线路详情
+ (void)loadLineDetailDataWithLineId:(NSString *)lineId success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestJavaBeanDataWithParams:@[API_App_Line_Detail,@{@"lineid":lineId?:@""}] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        LineDetailModel *object = [LineDetailModel mj_objectWithKeyValues:obj];
        if (success) {
            success(object);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//站点详情
+ (void)loadStationDetailDataWithStationId:(NSString *)stationId success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestJavaBeanDataWithParams:@[API_App_Station_Detail,@{@"stationid":stationId?:@""}] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        StationDetailModel *object = [StationDetailModel mj_objectWithKeyValues:obj];
        if (success) {
            success(object);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//标段详情
+ (void)loadSectionDetailDataWithSectionId:(NSString *)sectionId success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestJavaBeanDataWithParams:@[API_App_Section_Detail,@{@"sectionid":sectionId?:@""}] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        SectionDetailModel *object = [SectionDetailModel mj_objectWithKeyValues:obj];
        if (success) {
            success(object);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//工区详情
+ (void)loadFactoryDetailDataWithAreaId:(NSString *)areaId success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_WorkArea_Detail,areaId?:@""] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        WorkAreaDetailModel *object = [WorkAreaDetailModel mj_objectWithKeyValues:obj];
        if (success) {
            success(object);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//工区统计数据
+ (void)loadFactoryStatisticDataWithAreaId:(NSString *)areaId success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_WorkArea_Statistic,areaId?:@""] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        WorkAreaStatisticModel *object = [WorkAreaStatisticModel mj_objectWithKeyValues:obj];
        if (success) {
            success(object);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//标段列表 线路标识/站点id 二选一为idString
+ (void)loadLineSectionDataWithLineId:(NSString *)lineId stationId:(NSString *)stationId success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_Line_Section_List,lineId?:@"",stationId?:@""] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        NSArray *object = [SectionModel mj_objectArrayWithKeyValuesArray:[obj objectForKey:@"list"]];
        if (success) {
            success(object);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//工区人员列表
+ (void)loadFactoryUserListWithAreaId:(NSString *)areaId type:(NSString *)type pageNo:(NSString *)pageNo success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    
    [[NetworkTool sharedNetworkTool] requestJavaBeanDataWithParams:@[API_App_WorkArea_User_List,@{@"areaid":areaId?:@"",@"type":type?:@"",@"pageno":pageNo?:@""}] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        NSArray *object = [WorkAreaUserModel mj_objectArrayWithKeyValuesArray:[obj objectForKey:@"list"]];
        if (success) {
            success(object);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
    
//    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_WorkArea_User_List,areaId?:@"",type?:@"",pageNo?:@""] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
//        NSArray *object = [WorkAreaUserModel mj_objectArrayWithKeyValuesArray:[obj objectForKey:@"list"]];
//        if (success) {
//            success(object);
//        }
//    } Failure:^(NSString *code, NSString *msg) {
//        if (failure) {
//            failure(code,msg);
//        }
//    }];
}

//工区环境监测记录
+ (void)loadEnvironmentRecordListWithAreaId:(NSString *)areaId pageNo:(NSString *)pageNo success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_WorkArea_Environment_Record_List,areaId?:@"",pageNo?:@""] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        NSArray *object = [EnvironmentObserverModel mj_objectArrayWithKeyValuesArray:[obj objectForKey:@"list"]];
        if (success) {
            success(object);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//车辆进出记录
+ (void)loadCarAccessListDataWithQueryDate:(NSString *)queryDate pageNum:(NSString *)page areaId:(NSString *)areaId plateNum:(NSString *)plateNum success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_Car_Access_List,queryDate?:@"",areaId?:@"",plateNum?:@"",page?:@"1"] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        NSArray *object = [CarAccessModel mj_objectArrayWithKeyValuesArray:[obj objectForKey:@"list"]];
        if (success) {
            success(object);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//车辆进岗登记
+ (void)requestCarInWithPlateNum:(NSString *)plateNum driveName:(NSString *)driverName mobile:(NSString *)mobile driverCard:(NSString *)driverCard carType:(CarType)carType areaId:(NSString *)areaId note:(NSString *)note driverImage:(UIImage *)driverImage inTime:(NSString *)inTime inImage1:(UIImage *)image1 inImage2:(UIImage *)image2 success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    NSString *carTypeString = [NSString stringWithFormat:@"%ld",carType];
    
    RequestMessage *req = [[RequestMessage alloc] initWithFunc:API_App_Car_Access_In];
    req.header.httpheader = [MessageFactory getHttpHeader];
    [MessageFactory getHttpHeader].authtype = AUTH_LOGIN;
    [req.body setItemParaListWithIndex:plateNum?:@"",driverName?:@"",mobile?:@"",driverCard?:@"",inTime?:@"",carTypeString?:@"",areaId?:@"",note?:@"", nil];

//    if ([driverImage isKindOfClass:[UIImage class]]) {
        [req.body addImage:@"driver_img" image:driverImage];
//    }
//    if ([image1 isKindOfClass:[UIImage class]]) {
        [req.body addImage:@"in_img1" image:image1];
//    }
//    if ([image2 isKindOfClass:[UIImage class]]) {
        [req.body addImage:@"in_img2" image:image2];
//    }
    [MessageFactory doFormPost:req httpresult:^(ResponseMessage *res) {
        if ([res.header.status isEqualToString:@"200"]) {
            success(res.body.data);
        }else {
            failure(@"0",@"提交失败");
        }
        NSLog(@"车辆进岗登记结果\nstatus:%@,,info:%@",res.header.status,res.header.info);
    }];
}

//车辆离岗登记
+ (void)requestCarLogoutWithRecordId:(NSString *)recordId outTime:(NSString *)outTime outImage1:(UIImage *)image1 outImage2:(UIImage *)image2 success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    RequestMessage *req = [[RequestMessage alloc] initWithFunc:API_App_Car_Access_Out];
    req.header.httpheader = [MessageFactory getHttpHeader];
    [MessageFactory getHttpHeader].authtype = AUTH_LOGIN;
    req.header.datatype = JSON_ITEM;
    if (!image1 && !image2) {
        [req.body setItemParaListWithIndex:recordId?:@"",outTime?:@"",@"",@"", nil];
        [MessageFactory doPost:req httpresult:^(ResponseMessage *res) {
            if ([res.header.status isEqualToString:@"200"]) {
                success(res.body.data);
            }else {
                failure(@"0",@"提交失败");
            }
            NSLog(@"车辆离岗登记结果\nstatus:%@,,info:%@",res.header.status,res.header.info);
        }];
    }
    else {
        [req.body setItemParaListWithIndex:recordId?:@"",outTime?:@"", nil];
        [req.body addImage:@"out_img1" image:image1];
        [req.body addImage:@"out_img2" image:image2];
        [MessageFactory doFormPost:req httpresult:^(ResponseMessage *res) {
            if ([res.header.status isEqualToString:@"200"]) {
                success(res.body.data);
            }else {
                failure(@"0",@"提交失败");
            }
            NSLog(@"车辆离岗登记结果\nstatus:%@,,info:%@",res.header.status,res.header.info);
        }];
    }

}

//巡线照片
+ (void)loadPatrolLinePhotoListDataWithPage:(NSString *)page success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_Patrol_Line_List,page] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        NSArray *array = [PatrolLineModel mj_objectArrayWithKeyValuesArray:[obj objectForKey:@"list"]];
        if (success) {
            success(array);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//巡线拍照(上传视频或者图片)
+ (void)uploadPatrolLineDataWithAreaId:(NSString *)areaId deviceId:(NSString *)deviceId deviceName:(NSString *)deviceName channelName:(NSString *)cnName note:(NSString *)note image1:(UIImage *)image1 image2:(UIImage *)image2 image3:(UIImage *)image3 success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    RequestMessage *req = [[RequestMessage alloc] initWithFunc:API_App_Patrol_Line_Add];
    req.header.httpheader = [MessageFactory getHttpHeader];
    [MessageFactory getHttpHeader].authtype = AUTH_LOGIN;
    [req.body setItemParaListWithIndex:areaId?:@"",deviceId?:@"",deviceName?:@"",cnName?:@"",note?:@"", nil];
    [req.body addImage:@"snapshot_url1" image:image1];
    [req.body addImage:@"snapshot_url2" image:image2];
    [req.body addImage:@"snapshot_url3" image:image3];
    [req.body addImage:@"video_url" image:nil];
    [MessageFactory doFormPost:req httpresult:^(ResponseMessage *res) {
        if ([res.header.status isEqualToString:@"200"]) {
            success(res.body.data);
        }else {
            failure(@"0",@"提交失败");
        }
        NSLog(@"巡线拍照结果\nstatus:%@,,info:%@",res.header.status,res.header.info);
    }];
}

//删除巡线拍照
+ (void)deletePatrolLineDataWithSeqId:(NSString *)seqId success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestJavaBeanDataWithParams:@[API_App_Patrol_Line_Delete,@{@"seqid":seqId?:@""}] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        if (success) {
            success(obj);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//工区列表(树形)
+ (void)loadWorkareaListDataSuccess:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestJavaBeanDataWithParams:@[API_App_Workarea_Tree,@{}] authType:AUTH_LOGIN dataType:JSON_NO Success:^(id obj) {
        
        FactoryTreeModel *object = [FactoryTreeModel mj_objectWithKeyValues:obj];
        
        if (success) {
            success(object);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//采集人员列表
+ (void)loadGatherFaceUserListDataWithPageNo:(NSString *)pageNo keywork:(NSString *)keyword success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestJavaBeanDataWithParams:@[API_App_Face_List,@{@"keyword":keyword?:@"",@"pageno":pageNo?:@""}] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        NSArray *object = [SelectUserInfoModel mj_objectArrayWithKeyValuesArray:[obj objectForKey:@"list"]];
        if (success) {
            success(object);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//人脸采集
+ (void)uploadGatherFaceUserDataWithUserId:(NSString *)userId type:(NSInteger)type visitorName:(NSString *)visitorName image1:(UIImage *)image1 image2:(UIImage *)image2 image3:(UIImage *)image3 success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    RequestMessage *req = [[RequestMessage alloc] initWithFunc:API_App_Upload_Face];
    req.header.httpheader = [MessageFactory getHttpHeader];
    [MessageFactory getHttpHeader].authtype = AUTH_LOGIN;
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setObject:[@(type) stringValue] forKey:@"type"];
    [dict setObject:userId?:@"" forKey:@"user_account"];
    if (visitorName) {
        [dict setObject:visitorName?:@"" forKey:@"visitor_name"];
    }
    [req.body setItemWithDictionary:dict];
    if ([image1 isKindOfClass:[UIImage class]]) {
        [req.body addImage:@"face_img1" image:image1];
    }
    [req.body addImage:@"face_img2" image:image2];
    [req.body addImage:@"face_img3" image:image3];
    [MessageFactory doFormPost:req httpresult:^(ResponseMessage *res) {
        if ([res.header.status isEqualToString:@"200"]) {
            success(res.body.data);
        }else {
            failure(@"0",@"提交失败");
        }
        NSLog(@"人脸采集结果\nstatus:%@,,info:%@",res.header.status,res.header.info);
    }];
}

//删除人脸采集
+ (void)deleteFaceDataWithSeqid:(NSString *)seqid success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_Face_Delete,seqid?:@""] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        if (success) {
            success(obj);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//历史观看列表
/*
 0-30条记录
 1-1个月记录
 2-1周记录
 */
+ (void)loadHistoryWatchListDataWithType:(NSString *)type success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_User_History_See,type] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        NSArray *object = [SelectVideoDeviceModel mj_objectArrayWithKeyValuesArray:[obj objectForKey:@"list"]];
        for (SelectVideoDeviceModel *model in object) {
            if ([model isKindOfClass:[SelectVideoDeviceModel class]]) {
                [model setupTypeModel];
            }
        }
        if (success) {
            success(object);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//添加最近观看
+ (void)addHistoryWatchDataWithAreaId:(NSString *)areaId deviceId:(NSString *)deviceId deviceName:(NSString *)deviceName chName:(NSString *)chName success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_User_History_Add,areaId,deviceId,deviceName,chName] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        if (success) {
            success(obj);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//删除最近观看
+ (void)deleteHistoryWatchDataWithSeqId:(NSString *)seqId success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_User_History_Delete,seqId?:@""] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        if (success) {
            success(obj);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//新增视频历史观看记录
+ (void)addVideoHistoryDataWithDeviceId:(NSString *)deviceId areaId:(NSString *)areaId image:(UIImage *)image success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure{
    RequestMessage *req = [[RequestMessage alloc] initWithFunc:API_App_Video_History_Add];
    req.header.httpheader = [MessageFactory getHttpHeader];
    req.header.appcode = @"B000";
    [MessageFactory getHttpHeader].authtype = AUTH_LOGIN;
    [req.body setItemWithDictionary:@{
                                      @"deviceid":deviceId?:@"",
                                      @"areaid":areaId?:@"",
                                      }.mutableCopy];
    [req.body addImage:@"snapshot_img" image:image];
    
    [MessageFactory doFormPost:req httpresult:^(ResponseMessage *res) {
        if ([res.header.status isEqualToString:@"200"]) {
            success(res.body.data);
        }else {
            failure(@"0",@"提交失败");
        }
        NSLog(@"新增历史观看记录结果\nstatus:%@,,info:%@",res.header.status,res.header.info);
    }];
}

#pragma mark - 设备
/// 工区设备
+ (void)loadAreaDeviceListDataWithAreaId:(NSString *)areaId typeCode:(NSString *)typeCode pageNo:(NSString *)pageNo success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_Area_Device_List,areaId?:@"",typeCode?:@"",pageNo?:@""] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        NSArray *array = [DeviceStatisticModel mj_objectArrayWithKeyValuesArray:[obj objectForKey:@"list"]];
        if (success) {
            success(array);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

/// 设备领用列表
+ (void)loadDeviceUsedListDataWithKeyword:(NSString *)keyword pageNo:(NSString *)pageNo success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_Device_Use_List,keyword?:@"",pageNo?:@""] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        NSArray *array = [DeviceInfoModel mj_objectArrayWithKeyValuesArray:[obj objectForKey:@"list"]];
        if (success) {
            success(array);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

/// 选择设备列表
+ (void)loadSelectDeviceListDataWithKeyword:(NSString *)keyword pageNo:(NSString *)pageNo success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_Device_Pick_List,keyword?:@"",pageNo?:@""] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        NSArray *array = [DeviceInfoModel mj_objectArrayWithKeyValuesArray:[obj objectForKey:@"list"]];
        if (success) {
            success(array);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

/// 领用定位设备
+ (void)getLocateDeviceWithDeviceId:(NSString *)deviceId UserType:(NSString *)userType userAccount:(nullable NSString *)userAccount mobile:(nullable NSString *)mobile username:(nullable NSString *)username company:(nullable NSString *)company success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_Device_Locate_Used,deviceId?:@"",userType?:@"",userAccount?:@"",mobile?:@"",username?:@"",company?:@""] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        BaseModel *model = [BaseModel mj_objectWithKeyValues:obj];
        if (success) {
            success(model);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

/// 归还定位设备
+ (void)returnLocateDeviceWithDeviceId:(NSString *)deviceId success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_Device_Locate_Return,deviceId?:@""] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        BaseModel *model = [BaseModel mj_objectWithKeyValues:obj];
        if (success) {
            success(model);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

/// 人员领用设备列表 userAccount访客传空
+ (void)loadUserDeviceUsedListDataWithUserAccount:(nullable NSString *)userAccount mobile:(nullable NSString *)mobile areaId:(NSString *)areaId success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_Device_User_Used_List,userAccount?:@"",mobile?:@"",areaId?:@""] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        NSArray *model = [UserDeviceUsedModel mj_objectArrayWithKeyValuesArray:[obj objectForKey:@"list"]];
        if (success) {
            success(model);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

/// 获取设备领用信息
+ (void)loadDeviceUsedDetailDataWithDeviceId:(NSString *)deviceId success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_Device_Use_Detail,deviceId?:@""] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        DeviceUserdDetailModel *model = [DeviceUserdDetailModel mj_objectWithKeyValues:obj];
        if (success) {
            success(model);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

/// 获取设备领用人员列表
+ (void)loadDevicePickUserListDataWithKeyword:(NSString *)keyword pageNo:(NSString *)pageNo success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_Device_Pick_User_List,keyword?:@"",pageNo?:@""] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        NSArray *model = [DeviceUserInfoModel mj_objectArrayWithKeyValuesArray:[obj objectForKey:@"list"]];
        if (success) {
            success(model);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

+ (void)getTbkDeviceWithAccount:(NSString *)account userType:(NSString *)userType mobile:(NSString *)mobile userName:(NSString *)userName company:(NSString *)company deviceId:(NSString *)deviceId success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestJavaBeanDataWithParams:@[API_App_Device_Tbk_Used,@{@"account":account?:@"",@"user_type":userType?:@"",@"mobile":mobile?:@"",@"username":userName?:@"",@"company":company?:@"",@"deviceid":deviceId?:@""}] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        if (success) {
            success(obj);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

+ (void)returnTbkDeviceWithDeviceId:(NSString *)deviceId account:(NSString *)account success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestJavaBeanDataWithParams:@[API_App_Device_Tbk_Return,@{@"deviceid":deviceId?:@"",@"account":account?:@""}] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        if (success) {
            success(obj);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}

//获取对讲设备详情
+ (void)getTbkDeviceDetailWithDeviceId:(NSString *)deviceId success:(NetWorkSuccessBlock)success failure:(NetWorkFailureBlock)failure {
    [[NetworkTool sharedNetworkTool] requestDataWithParams:@[API_App_Device_Tbk_Detail,deviceId?:@""] authType:AUTH_LOGIN dataType:JSON_ITEM Success:^(id obj) {
        DeviceUserdDetailModel *model = [DeviceUserdDetailModel mj_objectWithKeyValues:obj];
        if (success) {
            success(model);
        }
    } Failure:^(NSString *code, NSString *msg) {
        if (failure) {
            failure(code,msg);
        }
    }];
}
@end
